package com.pangus.toolkits.files.request;

import lombok.Data;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * @author yingheng chen
 * @description
 * @date 2019/12/5
 */
@Data
public class Range {
    public static Range ALL = new Range(0L);
    @Nonnull
    private Long begin;
    @Nullable
    private Long end;

    public Range(@Nonnull Long begin, @Nullable Long end) {
        if (end != null) {
            if (end < begin) {
                throw new IllegalArgumentException("end can not be smaller than begin");
            }
            if (end < 0) {
                throw new IllegalArgumentException("end can not be negative");
            }
        }
        if (begin < 0) {
            throw new IllegalArgumentException("begin can not be negative");
        }
        this.begin = begin;
        this.end = end;
    }

    public Range(@Nonnull Long begin) {
        this(begin, null);
    }

    @Override
    public String toString() {
        if (end != null) {
            return begin + "-" + end;
        }
        return begin + "-";
    }
}
